
//
//  HJToResetViewController.m
//  Sneakers
//
//  Created by 胡光健 on 2017/11/21.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "HJToResetViewController.h"
#import "HJSettingViewController.h"

@interface HJToResetViewController ()
@property (weak, nonatomic) IBOutlet UITextField *oneP;

@property (weak, nonatomic) IBOutlet UIButton *okBtn;


@end

@implementation HJToResetViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"密码重置";
    
    self.okBtn.layer.shadowOpacity = 0.2;
    self.okBtn.layer.shadowRadius = 3;
    self.okBtn.layer.shadowOffset = CGSizeZero;
    self.okBtn.layer.shadowColor = [UIColor blackColor].CGColor;
    [[self.oneP.rac_textSignal filter:^BOOL(NSString*text){
        return text.length >= 6;
    }] subscribeNext:^(NSString *text){
        self.oneP.text = [text substringToIndex:6];
    }];
}

- (IBAction)ok:(UIButton *)sender {
    if (self.oneP.text.length<1) {
        [self showHint:@"请输入6位密码"];
        return;
    }
    [TZHttpTool post:PasswordAPI params:@{@"new_password":self.oneP.text,@"code":self.code,@"mobile":self.mobile} success:^(NSDictionary *result) {
        [self showHint:@"修改成功"];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            for (UIViewController * viewC in self.navigationController.viewControllers ) {
                if ([viewC isKindOfClass:[HJSettingViewController class]]) {
                     [self.navigationController popToViewController:viewC animated:YES];
                    break;
                }
            }
        });
    } failure:^(NSString *msg) {
        [self showErrorHUDWithError:msg];
    }];
}
@end
